`
https://leetcode.cn/problems/two-sum-iv-input-is-a-bst/
`

/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @param {number} k
 * @return {boolean}
 */
var findTarget = function (root, k) {
  if (!root.left && !root.right) return false

  const arr = []
  const traverse = (root) => {
    if (root === null) return
    traverse(root.left)
    arr.push(root.val)
    traverse(root.right)
  }
  traverse(root)

  let left = 0, right = arr.length - 1
  while (left < right) {
    const sum = arr[left] + arr[right]
    if (sum > k) {
      right--
    } else if (sum < k) {
      left++
    } else {
      return true
    }
  }

  return false
};